<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="baseurl" value="${pageContext.request.contextPath}/"></c:set>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="${baseurl}CSS/backMange.css">
<!-- 下拉 -->
<link rel="stylesheet" type="text/css"href="${baseurl}common/lowSelect/lib/css/htools.select.skin.css">
<!-- css资源 -->
<link rel="stylesheet" type="text/css" href="${baseurl}easyUI1.4.1/themes/default/easyui.css">
<!-- 图标资源 -->
<link rel="stylesheet" type="text/css" href="${baseurl}easyUI1.4.1/themes/icon.css">
<script type="text/javascript" src="${baseurl}easyUI1.4.1/jquery.min.js"></script>
<!-- 下拉 -->
<script type="text/javascript" src="${baseurl}common/lowSelect/lib/js/jquery.htools.select.js"></script>
<!--EasyUI的js包 -->
<script type="text/javascript" src="${baseurl}easyUI1.4.1/jquery.easyui.min.js"></script>
<!-- 本地语言 -->
<script type="text/javascript" src="${baseurl}easyUI1.4.1/locale/easyui-lang-zh_CN.js"></script>
<%@ include file="/WEB-INF/JSP/ajax.jsp"%>
<script type="text/javascript">
//IE不支持console对象，此代码仅为测试使用
///////////////////////////////////////
window.console = window.console || (function () {
var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile  
= c.clear = c.exception = c.trace = c.assert = function () { };  
return c;  
})();  
//当前ID
var role_list_roleId = '';
var role_list_roleName = '';
var power_frist = true;
var power_add_frist = true;
$(function(){
    //创建DataGrid
    $("#role_list_table").datagrid({
         url:'${baseurl}DrivingSys/role/list.action',  //数据来源 
         //冻结列
            columns:[[
                {field: 'ck', checkbox: true, width: '30' },  //复选框  
                {field:'roleCode',title:'角色编码',width:70,align:'center'},
                {field:'roleName',title:'角色名称',width:100,align:'center'},
                {field:'fisDelete',title:'是否可用',width:60
                	,align:'center',
		                    formatter:function(value,row,index){
		                        if(value == '0'){return '是'}
		             			else{return '否'}                        
		            }
                },
	            {field:'creatId',title:'创建人',width:50,align:'center'},
	            {field:'creatTime',title:'创建时间',width:125,align:'center'},
	            {field:'updateId',title:'修改人',width:50,align:'center'},
	            {field:'updateTime',title:'修改时间',width:125,align:'center'},
                {field:'remark',title:'备注',width:150,align:'center'},
	            {field:'id',title:'权限管理',width:150
                	,align:'center',
                    formatter:function(value,row,index){
                        return '<a href="#" class="easyui-linkbutton"onclick="findAllHandleByRole('+value+')" >查看权限</a>';                       
            		}
	            }
            ]],
            fitColumns:true,//自适应宽度，占满,不能和冻结列同时设置成true
            fit:true,//充满屏幕
            striped:true,   //斑马线效果
            idField:'id',    //主键列
            rownumbers:true,            //显示行号 
            singleSelect:false,          //是否单选
            //cache:false,				//关闭缓存
            method:'post',
            pagination:true,
            pageList:[10,20,50,100],//每页行数选择列表
            pageSize:20, //设置默认初始的每页行数rows
            pageNumber:1,//设置默认初始的页码page
            remoteSort:false,    //是否服务器端排序，设成false才可以在页面进行排序
            //sortName:'fisAdmin', //指定列名可以进行排序
            multiSort:true ,
            onLoadSuccess:function(){
	       		 $('#role_list_table').datagrid('clearSelections');
	       	},loadMsg:'请稍候...'

    });
    $("#power_list_table").treegrid({
    	url:'${baseurl}DrivingSys/power/handlelist.action',
    	method:'post',          //请求方式
        idField:'easyID',           //定义标识树节点的键名字段
        treeField:'name',       //定义树节点的字段
        fit:true,               //网格自动撑满
        fitColumns:true,        //设置为 true，则会自动扩大或缩小列的尺寸以适应网格的宽度并且防止水平滚动。
        animate:true,//是否用动画效果
        striped:true,   //斑马线效果
        singleSelect:false,          //是否单选
        
        collapsible:false,//是否可折叠
        showFooter:false,//是否使用页脚
        columns:[[
      			 {field: 'ck', checkbox:true, width: '30' },  //复选框  
      			 {field:'isUse',title:'已有',width:30
     	          	,align:'center',
     		                    formatter:function(value,row,index){
     		                    	if(value!=1){return ''}  
     					             else {return '<img style="width:20px; height:20px" src="${baseurl}easyUI1.4.1/themes/icons/ok.png">';}                        
     		             		}                       
     	         },
                 {field:'name',title:'名称',width:170,
      					formatter:function(value,row,index){
      	                    if(row.fisDelete == 1){
      	                    	value = '<span style="text-decoration:line-through;color:red">'+row.name+'</span>';
      	                    	return value;
      	                    }
      	         			else{
      	         				value = '<span >'+row.name+'</span>';
      	         				return value;
      	         			}                        
      	        		}
                  },
                  {field:'handleUrl',title:'操作路径',width:170,align:'left'}
              ]],
              onBeforeExpand:function(node){
      	    		return;
	      	  },
	      	  onDblClick:function(node){
	      	  },
	      	  onLoadSuccess:function(){
	      			$('#power_list_table').datagrid('clearSelections');
		        	power_frist = false;
	      	  }
    });
});
//////////////////////////////////////
</script>
</head>
<body style=" margin:0px;  overflow:hidden;">
	<table id="role_list_table"toolbar="#tb">
	</table>
	
	<div id="tb"style="background-color: #f5f5f5;">
		<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;padding-left:10px">
			<table>
				<tr >
					<td >
							<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">角色名</label>
							<input type="text"  placeholder="角色名称" id="role_name_id"
								style="width:60px;height:27px;margin-right:20px;margin-top: 5px;"/>
					</td>
					<td width="180px">
						<div style="float:left;margin:5px 5px 0 10px ;font-size:14px">是否可用</div>
						<select id="role_fisdelete_id">
							<option value="no" selected>全部&nbsp;</option>
							<option value="0">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="1">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
					<td>
						<input type="button"value="立即搜索" onclick="doSearch()"
							style="width:100px;height:32px;outline:none;border:none;background-image: url(${baseurl}images/myimages/button.jpg) ;background-position:0px -45px;cursor:pointer;color: #fff;border-radius:20px;padding:5px 21px"/>
					</td>
					<td></td>
				</tr>
				<tr>
				<shiro:hasPermission name="/role/add.action">
					<td align="left">
						<div class="button_cz" onclick="add()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xz.png"/></td>
									<td><div >新增</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				<shiro:hasPermission name="/role/update.action">
					<td>
						<div class="button_cz" onclick="edit()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >修改</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				<shiro:hasPermission name="/role/setdelete.action">
					<td>
						<div class="button_cz" onclick="setDelete('0')">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >启用</div></td>
								</tr>
							</table>
						</div>
					</td>
					<td>
						<div class="button_cz" onclick="setDelete('1')">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >停用</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
					<td>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<!-- 隐藏的添加窗口 -->
	<div id="add_window_div" class="easyui-window user_set_windows" title="添加角色" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:350px;height:210px;display:none">
		<div style="padding:5px 10px 0px 20px">
	    <form id="add_window_form" method="post"style="width:305px;height:170px">
	    	<table >
	    		<tr height="40px">
	    			<td width="30%" class="td_r"><b>*</b>角色名称:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_name_id" />
	        		</td>
	    		</tr>
	    		<tr height="40px">
	    			<td width="30%" class="td_r"><b>*</b>角色编码:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_code_id" />
	        		</td>
	    		</tr>
	    		<tr height="40px">
	    			<td width="30%" class="td_r">编码示例:</td>
	        		<td width="70%" class="td_l">
	        			<b>Driving_add_role</b>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">备注:</td>
	    			<td  width="70%" class="td_l">
	    			<textarea type="text"id="add_remark_id" style="width:100%;resize:none"></textarea>
	    			</td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="margin-right:100px;width:70px;height:30px;" onclick="submitForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="width:70px;height:30px;" onclick="javascript:$('#add_window_div').window('close')">关闭</a>
	    </div>
	    </div>
	</div>

	<div id="update_window_div" class="easyui-window user_set_windows" title="修改角色" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" 
			style="width:350px;height:280px;display:none">
		<div style="padding:5px 10px 0px 20px">
	    <form id="update_window_form" method="post"style="width:305px;height:210px">
	    	<table >
	    		<tr height="40px">
	    			<td width="30%" class="td_r"><b>*</b>角色名称:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="update_name_id" />
	        			<input type="text" style="display:none"id="update_RoleID_id" />
	        		</td>
	    		</tr>
	    		<tr height="40px">
	    			<td width="30%" class="td_r"><b>*</b>角色编码:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="update_code_id" />
	        		</td>
	    		</tr>
	    		<tr height="40px">
	    			<td width="30%" class="td_r">编码示例:</td>
	        		<td width="70%" class="td_l">
	        			<b>Driving_add_role</b>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">备注:</td>
	    			<td  width="70%" class="td_l">
	    			<textarea type="text"id="update_remark_id" style="width:100%;resize:none"></textarea>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>
						<div style="float:left;margin:5px 5px 0 10px ;font-size:14px">是否可用</div></td>
					<td>
						<select id="update_fisDelete_id"class="beautify_input">
							<option value="0">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="1">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
	    		</tr>
	    		
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="margin-right:100px;width:70px;height:30px;" onclick="updatesubmitForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="width:70px;height:30px;" onclick="javascript:$('#update_window_div').window('close')">关闭</a>
	    </div>
	    </div>
	</div>
	
	<!-- 权限管理 -->
	<div id="power_window_div" class="easyui-window user_set_windows" title="角色权限管理" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:50" 
			style="width:590px;height:450px;display:none">
			<table id="power_list_table"style="width:500px"toolbar="#power_tb">
			</table>
			<div id="power_tb">
				<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;">
					<table width="100%">
						<tr >
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">权限名称</label>
									<input type="text"  placeholder="权限名称" id="power_power_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td>
								<a href="#" class="easyui-linkbutton" 
											iconCls="icon-search"onclick="onefindAllHandleByRole()">搜索</a>
							</td>
							<!-- <td>
								<a href="#" class="easyui-linkbutton" iconCls="icon-search"onclick="findRoleData()">搜索</a>
							</td> -->
							<shiro:hasPermission name="/power/roleAddHandle.action">
							<td align="left">
								<div class="button_cz" onclick="toAddRole()">
									<table>
										<tr>
											<td><img src="${baseurl}images/myimages/xz.png"/></td>
											<td><div >添加权限</div></td>
										</tr>
									</table>
								</div>
							</td>
							</shiro:hasPermission>
							<shiro:hasPermission name="/power/roleDeleteHandle.action">
							<td>
								<div class="button_cz" onclick="toDeleteRole()">
									<table>
										<tr>
											<td><img src="${baseurl}images/myimages/sc.png"/></td>
											<td><div >移除权限</div></td>
										</tr>
									</table>
								</div>
							</td>
							</shiro:hasPermission>
						</tr>
					</table>
					
				</div>
			</div>
	</div>
	<!-- 添加权限 -->
<!-- 	<div id="add_power_window_div" class="easyui-window user_set_windows" title="添加权限" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:100" 
			style="width:550px;height:350px;display:none">
			<table id="add_power_list_table"toolbar="#add_power_tb"style="width:100%">
				
			</table>
			<div id="add_power_tb">
				<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;">
					<table width="100%">
						<tr>
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">权限名称</label>
									<input type="text"  placeholder="权限名称" id="power_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">所属菜单名称</label>
									<input type="text"  placeholder="所属菜单名称" id="power_menu_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td>
								<a href="#" class="easyui-linkbutton" 
											iconCls="icon-search"onclick="oneAddPowerList()">搜索</a>
							</td>
							<td>
								<input type="button"value="确定" onclick="toAddRole()"
									style="cursor:hand;background-color: #54a0ff;color: #fff;border-radius:20px;padding:5px 10px"/>
							</td>
						</tr>
					</table>
				</div>
			</div>
	</div> -->
<script>
var $searchDeleteSelect = $("#role_fisdelete_id");
/**
 * 初始化插件
 */
$searchDeleteSelect.goSelectInput({
    height: 30,
    width: 90
});
function toDeleteRole(){
	//所选的权限
    var rows = $('#power_list_table').datagrid('getSelections');
    if(rows.length <1){
  	  $.messager.alert("提示", "请至少选择一行！", "info");  
  	  return;
    }
    var names = "";
    var ids="";  
  //批量获取选中行的模板ID  
    for (i = 0; i < rows.length;i++) {
    	  if( rows[i].easyID.indexOf('m') >= 0){
  		    continue;
		  }
    	  //如果没有此权限跳过
    	  if( rows[i].isUse == 0){
    		    continue;
  		  }
	      if (ids =="") {
	      	  ids = rows[i].id;  
	      	  names = rows[i].name;  
	      } else {
	      	  ids = rows[i].id +"," + ids;
	      	  names = rows[i].name +"," + names;
	      }      
	      
    }
    if(ids == ""){
		$.messager.alert("提示", "没有可操作的行！", "info");  
	  	  return;
	}
	$.messager.confirm('提示', '是否将<b>'+names+'</b>移除?', function (r) {
	      if (!r) {
	           return;  
	      }
	      $.ajax({
		      url:'${baseurl}DrivingSys/power/roleDeleteHandle.action',  
		      type: "post",  
		      dataType:"json",
		      data:{"ids":ids,"roleId":role_list_roleId}, 
		      success: function(json) {
		    	  console.log(json);
		    	  if(json.success <=0 ){
			        	$.messager.alert('提示',json.error,'warning');
		          }else{
			        	$.messager.show({
							title:'提示',
							msg:'删除成功!',
							timeout:3000,
							showType:'slide'
						});
			        	onefindAllHandleByRole()
		          }
		      },error:function(){
		      	$.messager.progress('close');
		      	$.messager.alert('提示','请刷新页面重试!','warning');
		      }
		  });
		  
	     // roleadd
		  
	}); 
}

//添加权限
function toAddRole(){
	//所选的权限
    var rows = $('#power_list_table').datagrid('getSelections');
    if(rows.length <1){
  	  $.messager.alert("提示", "请至少选择一行！", "info");  
  	  return;
    }
	console.log(rows)
    var names = "";
    var ids="";  
	//批量获取选中行的模板ID  
    for (i = 0; i < rows.length;i++) {
    	  if( rows[i].easyID.indexOf('m') >= 0){
    		  continue;
		  }
    	  if( rows[i].isUse == 1){
  		    continue;
		  }
	      if (ids =="") {
	      	  ids = rows[i].id;  
	      	  names = rows[i].name;  
	      } else {
	      	  ids = rows[i].id +"," + ids;
	      	  names = rows[i].name +"," + names;
	      }      
	      
    }
	if(ids == ""){
		$.messager.alert("提示", "没有可操作的行！", "info");  
	  	  return;
	}
	$.messager.confirm('提示', '是否添加<b>'+names+'</b>?', function (r) {
	      if (!r) {
	           return;  
	      }
	      $.ajax({
		      url:'${baseurl}DrivingSys/power/roleAddHandle.action',  
		      type: "post",  
		      dataType:"json",
		      data:{"ids":ids,"roleId":role_list_roleId }, 
		      success: function(json) {
		    	  console.log(json);
		    	  if(json.success <=0 ){
			        	$.messager.alert('提示',json.error,'warning');
		          }else{
			        	$.messager.show({
							title:'提示',
							msg:'添加成功!',
							timeout:3000,
							showType:'slide'
						});
			        	onefindAllHandleByRole();
		          }
		      },error:function(){
		      	$.messager.progress('close');
		      	$.messager.alert('提示','请刷新页面重试!','warning');
		      }
		  });
		  
	     // roleadd
		  
	}); 
}


//设置权限的查询
/* function oneAddPowerList(){
	$('#add_power_list_table').datagrid('reload',{
		id: role_list_roleId,
		name:$("#power_name_id").val(),
		menuName:$("#power_menu_name_id").val()
	});
}
 */
//获取当前角色所有权限
function onefindAllHandleByRole(){
	$('#power_list_table').treegrid('resize',{
			width: 200
		});
	$('#power_list_table').treegrid('reload',{
			roleId: role_list_roleId,
			name:$("#power_power_name_id").val()
	});
}

//获取当前角色所有权限       窗口
function findAllHandleByRole(thisId){
	$("#power_power_name_id").val("");
	$("#power_name_id").val("");
	$("#power_menu_name_id").val("");
	role_list_roleId = thisId;
	/* $('#role_list_table').datagrid('clearSelections'); */
	$('#power_window_div').window('open');
	$('#power_window_div').attr('style','width:590px;height:450px;');
	$('#power_list_table').treegrid('resize',{
		width: 200
	});
	$('#power_list_table').treegrid('reload',{
		roleId: thisId
	});
	
}
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////增删改查部分///////////////////////////////////////////
//分页查询
function doSearch(){
	//清除用户checked项
	$('#role_list_table').datagrid('clearSelections');
	var roleName = $('#role_name_id').val();
	var fisDelete = $searchDeleteSelect.val();
	if(checkStr(roleName)||
			checkStr(fisDelete)){
		return;
	}
	//保留页码查询
	$('#role_list_table').datagrid('reload',{
		roleName: roleName,
		fisDelete: fisDelete
	});
}

function add(){
  	$('#add_name_id').val("");
	$("#add_code_id").val("");
	$("#add_remark_id").val("");
	$("#add_window_div").attr("style","width:350px;height:230px");
	$('#add_window_div').window('open');
}
function edit(){
	var thisBean = $('#role_list_table').datagrid('getSelections');
	if( thisBean.length == 0 || thisBean.length>1){
		$.messager.alert('提示','请正确选择修改行!');
		return;
	}
	var thisId = thisBean[0].id;
	$.ajax({
	      url:'${baseurl}DrivingSys/role/roledata.action',  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
	      data:{"id":thisId}, 
	      success: function(json) {
	    	$("#update_window_div").attr("style","width:350px;height:280px;");
	    	$('#update_window_div').window('open');
	      	var role = json.role;
	      	$("#update_RoleID_id").val(role.id);
	      	$('#update_fisDelete_id').val(role.fisDelete);
	      	$('#update_name_id').val(role.roleName);
	    	$("#update_code_id").val(role.roleCode);
	    	$("#update_remark_id").val(role.remark);
	      	
	      },error:function(){
	      	$.messager.progress('close');
	      	$.messager.alert('提示','请刷新页面重试!','warning');
	      }
	  });
}
function checkStr(str){
	var patrn=/[!#@$%^&*()_+<>?:"{},\/;'[\]]/;
	if(patrn.test(str)){
		$.messager.alert('提示','请不要使用非中文符号!');
		return true;     
	}
	return false;
}
//启用停用
function setDelete(isDelete){
		var selRow = $('#role_list_table').datagrid('getSelections') ;
		if (selRow.length==0) {
	      $.messager.alert("提示", "请选择要操作的行！", "info");  
	      return;  
    	}
		var ids="";  
		//批量获取选中行的评估模板ID  
	    for (i = 0; i < selRow.length;i++) {
		  	if(isDelete == '0'&& selRow[i].fisDelete == '0'){
		  		continue;
		  	}
		  	if(isDelete == '1'&& selRow[i].fisDelete == '1'){
		  		continue;
		  	}
		    if (ids =="") {  
		      	ids = selRow[i].id;  
		    } else {
		      	ids = selRow[i].id +"," + ids;  
		    }      
	    }  
		if(ids == ""){
		  	$.messager.alert("提示", "选中的可用户必须大于一人！", "info"); 
		  	return;
		}
		
		$.ajax({
	        url:'${baseurl}DrivingSys/role/setdelete.action',  
	        type: "post",  
	        dataType:"json",
		    data:{"ids":ids,"isDelete":isDelete}, 
	        success: function(json) {
	        	if(json.success == undefined || json.success == 'undefined'){
		        	$.messager.alert('提示','操作失败，请刷新页面重试!','warning');
	        	}else{
		        	$.messager.show({
						title:'提示',
						msg:'设置成功!',
						timeout:3000,
						showType:'slide'
					});
		        	doSearch();
	        	}
	        },error:function(){
	        	$.messager.progress('close');
	        	$.messager.alert('提示','操作失败，请刷新页面重试!','warning');
	        }
	    })
}
//修改提交并验证表单
function updatesubmitForm(){
	var id = $('#update_RoleID_id').val();
	var roleName = $('#update_name_id').val();
	var roleCode = $("#update_code_id").val();
	var remark = $("#update_remark_id").val();
	var fisDelete = $('#update_fisDelete_id').val();
	if(roleName ==null || roleName == "" ||
		roleCode ==null || roleCode == ""){
		$.messager.alert('提示','角色名和角色编号必须填写!');
		return;
	}
	if(checkStr(roleName)||
			checkStr(remark)){
		return;
	}
	var patrn=/[!#@$%^&*()+<>?:"{},\/;'[\]]/;
	if(patrn.test(roleCode)){
		$.messager.alert('提示','编号只能使用横杠和下划线!');
		return true;     
	}
	if(roleCode == 'admin_role'){
		$.messager.alert('提示','此编号为限定编号，请重新输入!');
		return true; 
	}
	$.ajax({
	      url:'${baseurl}DrivingSys/role/update.action',  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
		    data:{"id":id,"roleName":roleName,"roleCode":roleCode,
		    	  "remark":remark,"fisDelete":fisDelete}, 
	      success: function(json) {
	    	if(json.success > 0){
	    		$('#update_window_div').window('close');
		      	$.messager.show({
					title:'提示',
					msg:'修改成功!',
					timeout:3000,
					showType:'slide'
				});
		      	doSearch();
	    	}else if (json.success == 0){
	    		$.messager.alert('提示','角色编码重复!','warning');
	    	}else{
	    		$.messager.alert('提示','插入失败!','warning');
	    	}
	      	
	      },error:function(){
	      	$.messager.progress('close');
	      	$.messager.alert('提示','请刷新页面重试!','warning');
	      }
	  });
}

//提交并验证表单
function submitForm(){
	var roleName = $('#add_name_id').val();
	var roleCode = $("#add_code_id").val();
	var remark = $("#add_remark_id").val();
	if(roleName ==null || roleName == "" ||
		roleCode ==null || roleCode == ""){
		$.messager.alert('提示','角色名和角色编号必须填写!');
		return;
	}
	if(checkStr(roleName)||
			checkStr(remark)){
		return;
	}
	var patrn=/[ `~!@#$%^&*()+=|{}':;',\\[\\].<>\/?~！@#￥%……&*（）+|{}【】‘；：”“’。，、？]/;
	if(patrn.test(roleCode)){
		$.messager.alert('提示','编号只能使用横杠和下划线!');
		return true;     
	}
	if(roleCode == 'admin_role'){
		$.messager.alert('提示','此编号为限定编号，请重新输入!');
		return true; 
	}
	$.ajax({
	      url:'${baseurl}DrivingSys/role/add.action',  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
		    data:{"roleName":roleName,"roleCode":roleCode,
		    	  "remark":remark}, 
	      success: function(json) {
	    	  if(json.success == 'success'){
	    		  $('#add_window_div').window('close');
		  	      $.messager.show({
		  				title:'提示',
		  				msg:'添加成功!',
		  				timeout:3000,
		  				showType:'slide'
		  		  });
		  	      doSearch();
	    	  }else if(json.success == "notInsert"){
	    		  $.messager.alert('提示','角色编码重复无法插入!','warning');
	    	  }
	      	
	      },error:function(){
	      	  $.messager.progress('close');
	      	  $.messager.alert('提示','请刷新页面重试!','warning');
	      }
	  });
}
</script>
</body>
</html>